package com.github.linkoog.model_designer.ide.editer.common;

import com.intellij.openapi.util.IconLoader;
import com.intellij.util.xml.NamedEnum;

import javax.swing.*;

public enum DataType implements NamedEnum {

    CHAR("char", IconLoader.getIcon("/icons/data-type/string.svg",DataType.class)),
    VARCHAR("varchar", IconLoader.getIcon("/icons/data-type/string.svg",DataType.class)),
    TEXT("text", IconLoader.getIcon("/icons/data-type/string.svg",DataType.class)),

    TINYINT("tinyint", IconLoader.getIcon("/icons/data-type/number.svg",DataType.class)),
    SMALLINT("smallint", IconLoader.getIcon("/icons/data-type/number.svg",DataType.class)),
    INT("int", IconLoader.getIcon("/icons/data-type/number.svg",DataType.class)),
    BIGINT("bigint", IconLoader.getIcon("/icons/data-type/number.svg",DataType.class)),

    DECIMAL("decimal", IconLoader.getIcon("/icons/data-type/number.svg",DataType.class)),


    DATE("date", IconLoader.getIcon("/icons/data-type/date.svg",DataType.class)),
    TIME("time", IconLoader.getIcon("/icons/data-type/date.svg",DataType.class)),
    DATETIME("datetime", IconLoader.getIcon("/icons/data-type/date.svg",DataType.class))
    ;

    private String name;
    private Icon icon;

    private DataType(String name,Icon icon){
        this.name = name;
        this.icon = icon;
    }

    public String getName() {
        return name;
    }

    public Icon getIcon() {
        return icon;
    }

    @Override
    public String getValue() {
        return name;
    }

    public static DataType valueOfName(String name){
        for (DataType dataType : DataType.values()) {
            if (dataType.getName().equals(name)){
                return dataType;
            }
        }
        return null;
    }
}
